<?
 set_time_limit(1500);

 require "stats.inc.php"; 
 require "stats-aggreg.inc.php";  
 
 if(file_exists(dirname(__FILE__)."/stats.serialized"))
 {
   $stats = unserialize(file_get_contents(dirname(__FILE__)."/stats.serialized"));
 }
 else
 {
	$stats = new stats; 
	$alpha = new dns_server("alpha");
	$gamma = new dns_server("gamma");
	$stats->add_dnsserver($alpha);
	$stats->add_dnsserver($gamma);
	$alpha = null;
	$gamma = null; 
 }
 
 // update
	$farr = array(
		"alpha" => "alpha.log",
		"gamma" => "gamma.log"
	);

	$parr = $stats->get_full_poollist();

	$d = $_GET['date'];

	foreach($farr as $s => $f)
	{
		foreach($parr as $p)
		{
			$a = new generate_dns_stats($s, $f, $d, $p[0], $p[1]);
			$stats->get_dnsserver($s)->insert_stats($a->get_statsobj());
			$a = null;
		} 
	}

	$statsagg = new stats_aggregation;
	$statsagg->update_aggregate($stats);


 file_put_contents(dirname(__FILE__)."/stats.serialized",serialize($stats));
 file_put_contents(dirname(__FILE__)."/stats-aggreg.serialized",serialize($statsagg));

echo "UPDATED"; 
?>
